# !/usr/bin/env python3
# -*- coding: utf-8 -*-

# @Time : 2022/12/16 09:14

# @Author : ylliu
# @Email :
# @File : aux_tbl_structure.py
# @Version: planner_builder 1.0


import ctypes

c_uint32 = ctypes.c_uint32

class AuxEntry_bits(ctypes.BigEndianStructure):
    _fields_ = [
        # entry1
        ('reserved1', c_uint32, 18),
        ('rx_flowid_p0', c_uint32, 14),
        # entry2
        ('reserved2', c_uint32, 18),
        ('rx_flowid_p1', c_uint32, 14),
        # entry3
        ('reserved3', c_uint32, 18),
        ('rx_flowid_p2', c_uint32, 14),
        # entry4
        ('reserved4', c_uint32, 18),
        ('rx_flowid_p3', c_uint32, 14),
        # entry5
        ('reserved5', c_uint32, 18),
        ('tx_flowid_p0', c_uint32, 14),
        # entry6
        ('reserved6', c_uint32, 18),
        ('tx_flowid_p1', c_uint32, 14),
        # entry7
        ('reserved7', c_uint32, 18),
        ('tx_flowid_p2', c_uint32, 14),
        # entry8
        ('reserved8', c_uint32, 18),
        ('tx_flowid_p3', c_uint32, 14),
        # entry9
        ('reserved9', c_uint32, 25),
        ('pto_select', c_uint32, 1),
        ('tx_pulse', c_uint32, 3),
        ('rx_pulse', c_uint32, 3),
        # entry 10
        ('reserved10', c_uint32, 16),
        ('dmac_1', c_uint32, 16),  # dmac的高16bit
        # entry11
        ('dmac_2', c_uint32, 32),  # dmac的低32bit
        # entry 12
        ('reserved11', c_uint32, 30),
        ('mirror_mode', c_uint32, 2),
        # entry 13
        ('reserved12', c_uint32, 17),
        ('valid0', c_uint32, 1),
        ('flow_id_0', c_uint32, 14),
        # entry 14
        ('reserved13', c_uint32, 17),
        ('valid1', c_uint32, 1),
        ('flow_id_1', c_uint32, 14),
        # entry 15
        ('reserved14', c_uint32, 17),
        ('valid2', c_uint32, 1),
        ('flow_id_2', c_uint32, 14),
        # entry 16
        ('reserved15', c_uint32, 17),
        ('valid3', c_uint32, 1),
        ('flow_id_3', c_uint32, 14),
        # entry 17
        ('reserved16', c_uint32, 17),
        ('valid4', c_uint32, 1),
        ('flow_id_4', c_uint32, 14),
        # entry 18
        ('reserved17', c_uint32, 17),
        ('valid5', c_uint32, 1),
        ('flow_id_5', c_uint32, 14),
        # entry 19
        ('reserved18', c_uint32, 17),
        ('valid6', c_uint32, 1),
        ('flow_id_6', c_uint32, 14),
        # entry 20
        ('reserved19', c_uint32, 17),
        ('valid7', c_uint32, 1),
        ('flow_id_7', c_uint32, 14),
        # entry 21
        ('reserved20', c_uint32, 17),
        ('valid8', c_uint32, 1),
        ('flow_id_8', c_uint32, 14),
        # entry 22
        ('reserved21', c_uint32, 17),
        ('valid9', c_uint32, 1),
        ('flow_id_9', c_uint32, 14),
        # entry 23
        ('reserved22', c_uint32, 17),
        ('valid10', c_uint32, 1),
        ('flow_id_10', c_uint32, 14),
        # entry 24
        ('reserved23', c_uint32, 17),
        ('valid11', c_uint32, 1),
        ('flow_id_11', c_uint32, 14),
        # entry 25
        ('reserved24', c_uint32, 17),
        ('valid12', c_uint32, 1),
        ('flow_id_12', c_uint32, 14),
        # entry 26
        ('reserved25', c_uint32, 17),
        ('valid13', c_uint32, 1),
        ('flow_id_13', c_uint32, 14),
        # entry 27
        ('reserved26', c_uint32, 17),
        ('valid14', c_uint32, 1),
        ('flow_id_14', c_uint32, 14),
        # entry 28
        ('reserved27', c_uint32, 17),
        ('valid15', c_uint32, 1),
        ('flow_id_15', c_uint32, 14)
    ]

class AuxEntry_bytes(ctypes.BigEndianStructure):
    _fields_ = [
        ('entry1', c_uint32, 32),
        ('entry2', c_uint32, 32),
        ('entry3', c_uint32, 32),
        ('entry4', c_uint32, 32),
        ('entry5', c_uint32, 32),
        ('entry6', c_uint32, 32),
        ('entry7', c_uint32, 32),
        ('entry8', c_uint32, 32),
        ('entry9', c_uint32, 32),
        ('entry10', c_uint32, 32),
        ('entry11', c_uint32, 32),
        ('entry12', c_uint32, 32),
        ('entry13', c_uint32, 32),
        ('entry14', c_uint32, 32),
        ('entry15', c_uint32, 32),
        ('entry16', c_uint32, 32),
        ('entry17', c_uint32, 32),
        ('entry18', c_uint32, 32),
        ('entry19', c_uint32, 32),
        ('entry20', c_uint32, 32),
        ('entry21', c_uint32, 32),
        ('entry22', c_uint32, 32),
        ('entry23', c_uint32, 32),
        ('entry24', c_uint32, 32),
        ('entry25', c_uint32, 32),
        ('entry26', c_uint32, 32),
        ('entry27', c_uint32, 32),
        ('entry28', c_uint32, 32)
    ]

class AuxEntry_union(ctypes.Union):
    _fields_ = [
        ('bit', AuxEntry_bits),
        ('byte', AuxEntry_bytes)
    ]



class AuxTblEachNode:
    def __init__(self,
                 node_id: int):
        self.node_id = node_id
        self.tbl_each_node = []

    def append_entry(self,
                     entry: AuxEntry_union):
        self.tbl_each_node.append(entry)


class AuxTbl:
    def __init__(self):
        self.tbl_set = []

    def append_tbl(self,
                   tbl: AuxTblEachNode):
        self.tbl_set.append(tbl)